#!/bin/bash
TotalA=`cat /proc/stat | sed -n '1p' | awk '{print $2+$3+$4+$5+$6+$7+$8}'`
IDLEA=`cat /proc/stat |sed -n '1p' |awk '{print $5}'`
sleep 2
TotalB=`cat /proc/stat | sed -n '1p' | awk '{print $2+$3+$4+$5+$6+$7+$8}'`
IDLEB=`cat /proc/stat |sed -n '1p' |awk '{print $5}'`
Total=`echo "$TotalB-$TotalA" |bc`
Idle=`echo "$IDLEB-$IDLEA" |bc`
USAGE=`echo "$Idle/$Total*100"|bc -l`
RATE=`echo "100-$USAGE "|bc -l`
USERATE=`echo "scale=2;$RATE/1"|bc`%
echo $USERATE
